package com.baimo.support.service.impl;

import com.baimo.support.api.mysql.ContextConst;
import com.baimo.support.api.mysql.DataSource;
import com.baimo.support.bean.BaseBean;
import com.baimo.support.bean.PageModel;
import com.baimo.support.dao.mapper.PrimaryUserMapper;
import com.baimo.support.dao.mapper.UserReviewMapper;
import com.baimo.support.dao.model.UserReviewModel;
import com.baimo.support.dao.model.UserTempModel;
import com.baimo.support.service.IUserService;
import com.baimo.support.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 品牌功能Controller
 * Created by wang on 2019/11/20.
 */
@Service
public class IUserServiceImpl extends BaseService implements IUserService {


    @Override
    @DataSource(ContextConst.DataSourceType.PRIMARY)
    public BaseBean getTempUser(HttpServletRequest request, HttpServletResponse response) {
        String limit = request.getParameter("limit");
        String offset = request.getParameter("offset");

        String insertStatus = request.getParameter("insertStatus");
        //如果分割limit或者offset 为空的话,则不展示数据
        List<UserTempModel> results = primaryUserMapper.findTempUser(insertStatus, StringUtils.formatStringToInt(limit),StringUtils.formatStringToInt(offset));
        if(results == null || results.size() < 1 ) return new BaseBean();

        PageModel<UserTempModel> pages = new PageModel();
        pages.setRows(results);
        pages.setTotal(results.size());
        return pages;
    }


    @Override
    @DataSource(ContextConst.DataSourceType.PROD)
    public List<UserReviewModel> findAllUserReviews() {
        return userReviewMapper.findAllUserReview();
    }
}
